class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def btreeGameWinningMove(self, root, n, x):
        """
        :type root: TreeNode
        :type n: int
        :type x: int
        :rtype: bool
        """
        def count(node):
            left_val = 0
            right_val = 0
            if node.left:
                left_val = count(node.left)
            if node.right:
                right_val = count(node.right)
            now_val = left_val + right_val + 1
            if node.val == x:
                self.max_val = max(n - now_val, left_val, right_val)
            return now_val

        count(root)
        return self.max_val > n // 2

